package com.sunstar.koobaselib.kootl.rvItemtouch.model;

import com.sunstar.koobaselib.kootl.comm.base.BaseCallBack;
import com.sunstar.koobaselib.kootl.comm.config.CommFinalData;
import com.sunstar.koobaselib.kootl.comm.helper.CacheHelper;
import com.sunstar.koobaselib.kootl.rvItemtouch.adapter.ItemTouchHelperRVAdapter;
import com.sunstar.koobaselib.kootl.rvItemtouch.bean.ItemTouchBean;
import com.sunstar.koobaselib.kootl.rvItemtouch.contract.ItemTouchContract;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by louisgeek on 2016/12/30
 */

public class ItemTouchModelImpl implements ItemTouchContract.Model<List<ItemTouchBean>> {


    @Override
    public void loadDataBase(String url, int pageNum, int pageSize, String queryKey, BaseCallBack<List<ItemTouchBean>> baseCallBack) {


        /**
         * 取得缓存
         */
        List<ItemTouchBean> itemTouchBeanList = CacheHelper.getData(CommFinalData.CACHE_NEWS_CHANNEL);
        if (itemTouchBeanList == null) {
            itemTouchBeanList = new ArrayList<>();
            for (int i = 0; i < 20; i++) {
                ItemTouchBean itemTouchBean = new ItemTouchBean();
                itemTouchBean.setId(i);
                if (i == 0) {
                    itemTouchBean.setViewType(ItemTouchHelperRVAdapter.VIEW_TYPE_MY_TITLE);
                    itemTouchBean.setText("我的订阅");
                    itemTouchBean.setText2("单击增删订阅，长按拖拽排序");
                } else if (i > 0 && i < 12) {
                    itemTouchBean.setViewType(ItemTouchHelperRVAdapter.VIEW_TYPE_MY_LIST);
                    itemTouchBean.setText("sss" + i);
                    itemTouchBean.setText2("fff" + i);
                } else if (i == 12) {
                    itemTouchBean.setViewType(ItemTouchHelperRVAdapter.VIEW_TYPE_MORE_TITLE);
                    itemTouchBean.setText("更多订阅");
                    itemTouchBean.setText2("");
                } else if (i > 12) {
                    itemTouchBean.setViewType(ItemTouchHelperRVAdapter.VIEW_TYPE_MORE_LIST);
                    itemTouchBean.setText("sss" + i);
                    itemTouchBean.setText2("fff" + i);
                }
                itemTouchBeanList.add(itemTouchBean);
            }
        }

        baseCallBack.onSuccess(itemTouchBeanList);
    }
}